Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent incorrect gppSection being set #4823

Merged
merged 10 commits into from
Apr 23, 2024

Conversation

gilluminate
Copy link
Contributor

@gilluminate gilluminate commented Apr 22, 2024

Closes #PROD-1913

Description Of Changes

US National should only ever be a parsed section if the US National approach is selected in Management > Consent

Code Changes

  • return [] early if approach is set to state and the region is "us"

Steps to Confirm

  1. Enable GPP in Fides by setting the appropriate env vars
  2. Run Fides Plus
  3. Go to Management > Consent
  4. Select the GPP state by state approach
  5. Edit a privacy experience to add a GPP notice
  6. Add “United States” as a location for the notice
  7. Go to the consent test page or cookie house and append a geolocation param for a state that is not part of GPP (US-NY, for example)
  8. Open the browser console and run __gpp('ping', ({parsedSections}) => {console.log(parsedSections)})

You should see an empty array [] instead of usnatv1 in the parsed sections.

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Issue Requirements are Met
  • Update CHANGELOG.md

Copy link

vercel bot commented Apr 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2024 5:37pm

@gilluminate gilluminate force-pushed the PROD-1913-gpp-us-national-section-should branch from 5daac54 to c59c876 Compare April 22, 2024 19:59
Copy link

cypress bot commented Apr 22, 2024

Passing run #7417 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge f8850c1 into 3cd817f...
Project: fides Commit: 9ce99841b6 ℹ️
Status: Passed Duration: 00:36 💡
Started: Apr 23, 2024 5:51 PM Ended: Apr 23, 2024 5:51 PM

Review all test suite changes for PR #4823 ↗︎

@gilluminate gilluminate force-pushed the PROD-1913-gpp-us-national-section-should branch 2 times, most recently from e9c1d5f to 56ad9b2 Compare April 22, 2024 20:37
@gilluminate gilluminate force-pushed the PROD-1913-gpp-us-national-section-should branch from 56ad9b2 to c4b4214 Compare April 22, 2024 20:50
@gilluminate gilluminate marked this pull request as draft April 22, 2024 21:05
@gilluminate gilluminate force-pushed the PROD-1913-gpp-us-national-section-should branch 2 times, most recently from ff5215b to 5c4bc47 Compare April 22, 2024 22:39
@gilluminate gilluminate force-pushed the PROD-1913-gpp-us-national-section-should branch 2 times, most recently from 1e9daa3 to d7785ad Compare April 22, 2024 22:54
@@ -76,7 +76,7 @@ const mockPrivacyExperience = (override?: Partial<PrivacyExperience>) => {
updated_at: "2023-12-07T22:03:26.052630+00:00",
gpp_settings: {
enabled: true,
us_approach: GPPUSApproach.STATE,
us_approach: GPPUSApproach.NATIONAL,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on this bug description, all of the tests were running incorrectly by using the state approach. none of these should pass with that enabled!

Comment on lines -586 to -593
gpp_settings: {
enabled: true,
us_approach: GPPUSApproach.NATIONAL, // But set setting to national
mspa_covered_transactions: true,
mspa_opt_out_option_mode: true,
mspa_service_provider_mode: false,
enable_tcfeu_string: true,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the default now

Comment on lines -123 to -125

// Whether the developer forced the inclusion of the GPP extension via query param on the script tag
forceGpp: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this bug fix, GPP doesn't really need to care if forceGpp is on or not, it will now be correct no matter what.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love that we have less overall code!

Comment on lines 89 to 92
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's where the bug was fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding these helpful comments, very easy to follow :)

(forceGpp && !experience?.gpp_settings) ||
experience?.gpp_settings?.us_approach === GPPUSApproach.STATE
) {
cmpApi.setApplicableSections([-1]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic for this was moved up where other applicable sections were being set, to avoid confusion

Comment on lines 144 to 147
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fix needed in both places. we should consider consolidating these 2 methods!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should at last consolidate a check for experienceRegion being in the US

@gilluminate gilluminate marked this pull request as ready for review April 23, 2024 00:03
Comment on lines -165 to -174

## Forcing GPP Inclusion

In some cases it may be necessary to always support the IAB's Global Privacy Platform (GPP), even if a visiting user is from a location without a privacy regulation. Forcing the inclusion of the [GPP API](/docs/tutorials/consent-management/consent-management-configuration/cmp-javascript-apis#gpp-api) can be accomplished by including query parameter `gpp=true` on the FidesJS script:

```
<script src="path/to/fides.js?gpp=true"></script>
```

When the GPP API is included this way, the `applicableSections` property is set to `[-1]` whenever a user visits a page from a non-supported location.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to move this. can't do arbitrary documentation here, since it gets auto-generated from the fides-js jsdocs. Moved this to a direct add in the fidesdocs repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right. This is always a point of confusion actually. Where to add docs / what will get autogenerated etc 😢

Comment on lines +171 to +173
if (!tcSet && !sectionsSet.length && !sectionsChanged.length) {
cmpApi.setApplicableSections([-1]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic moved here

Comment on lines 55 to 58
if (
experienceRegion?.toLowerCase().startsWith("us") &&
usApproach === GPPUSApproach.NATIONAL
) {
Copy link
Contributor Author

@gilluminate gilluminate Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-US regions were slipping through if force gpp was true. making sure it's a U.S. region before forcing this setting.

Copy link
Contributor

@eastandwestwind eastandwestwind Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better / more robust way to check for "US" regions? If not can we at least add a shared method / util for this so it's more documented?

Copy link
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding unit tests! Would like to just consolidate / clarify some logic, see notes below.

Comment on lines -165 to -174

## Forcing GPP Inclusion

In some cases it may be necessary to always support the IAB's Global Privacy Platform (GPP), even if a visiting user is from a location without a privacy regulation. Forcing the inclusion of the [GPP API](/docs/tutorials/consent-management/consent-management-configuration/cmp-javascript-apis#gpp-api) can be accomplished by including query parameter `gpp=true` on the FidesJS script:

```
<script src="path/to/fides.js?gpp=true"></script>
```

When the GPP API is included this way, the `applicableSections` property is set to `[-1]` whenever a user visits a page from a non-supported location.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right. This is always a point of confusion actually. Where to add docs / what will get autogenerated etc 😢

Comment on lines 89 to 92
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding these helpful comments, very easy to follow :)

Comment on lines 55 to 58
if (
experienceRegion?.toLowerCase().startsWith("us") &&
usApproach === GPPUSApproach.NATIONAL
) {
Copy link
Contributor

@eastandwestwind eastandwestwind Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better / more robust way to check for "US" regions? If not can we at least add a shared method / util for this so it's more documented?

}
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to work if experienceRegion is something like "us_ny"? Can we follow the same approach we use on L 56?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

experienceRegion here is the result of what's happening in L 56 so "us_ny" gets converted to "us" up there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh crap! I just realized that's not the case. This needs to be gppRegion!

Comment on lines 144 to 147
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above ^

Comment on lines 144 to 147
if (
!gppSection ||
(experienceRegion === "us" && usApproach === GPPUSApproach.STATE)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should at last consolidate a check for experienceRegion being in the US

Comment on lines -123 to -125

// Whether the developer forced the inclusion of the GPP extension via query param on the script tag
forceGpp: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love that we have less overall code!

@@ -356,7 +356,7 @@ describe("Fides-js GPP extension", () => {
supportedAPIs,
} = data.pingData;
expect(signalStatus).to.eql("ready");
expect(applicableSections).to.eql([]);
expect(applicableSections).to.eql([-1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gilluminate gilluminate merged commit d108ebe into main Apr 23, 2024
13 checks passed
@gilluminate gilluminate deleted the PROD-1913-gpp-us-national-section-should branch April 23, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants